package com.atguigu.common_utils;

import com.baomidou.mybatisplus.extension.api.R;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhj
 * @Title:
 * @Package
 * @Description:
 * @date 2021/10/18下午8:41
 */
@Data
public class Response {
    @ApiModelProperty(value = "是否成功")
    private Boolean success;
    @ApiModelProperty(value = "响应码")
    private Integer code;
    @ApiModelProperty(value = "返回消息")
    private String message;
    @ApiModelProperty(value = "返回数据")
    private Map<String, Object> data = new HashMap<>();
    private Response(){}

    public static Response ok(){
        Response response = new Response();
        response.setSuccess(true);
        response.setCode(ResultCode.SUCCESS);
        response.setMessage("成功");
        return response;
    }
    public static Response err(){
        Response response = new Response();
        response.setSuccess(false);
        response.setCode(ResultCode.ERROR);
        response.setMessage("失败");
        return response;

    }

    public Response success(Boolean success){
        this.setSuccess(success);
        return this;
    }
    public Response message(String message){
        this.setMessage(message);
        return this;
    }
    public Response code(Integer code){
        this.setCode(code);
        return this;
    }
    public Response data(Map<String,Object> map){
        this.setData(map);
        return this;
    }
    public Response data(String key,Object value){
        this.data.put(key,value);
        return this;
    }

}






